package com.lizhenhua.stockupdate.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.lizhenhua.fmmall.entity.ProductSku;
import com.lizhenhua.stockupdate.mapper.ProductSkuMapper;
import com.lizhenhua.stockupdate.service.StockUpdateService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class StockUpdateServiceImpl implements StockUpdateService {
    @Autowired
    private ProductSkuMapper skuMapper;

    @Override
    @Transactional    // 和下面Lcn 一起用
    @LcnTransaction  // lcn模式 分布式事务注解
    public int updateStock(List<ProductSku> skus) {
        int j = 1;
        for (ProductSku productSku : skus
        ) {
            int k = skuMapper.updateByPrimaryKeySelective(productSku);
            j *= k;
        }


        return j;
    }
}
